package com.xiaoli.orderserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoli.goods.api.IGoodsClient;
import com.xiaoli.orderserver.entity.Order;
import com.xiaoli.orderserver.mapper.OrderMapper;
import com.xiaoli.orderserver.service.IOrderService;
import com.xiaoli.user.api.IUserClient;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    private IUserClient userClient;

    @Autowired
    private IGoodsClient goodsClient;

    @GlobalTransactional
    @Override
    public void submitOrder() {
        log.info("扣减库存----begin");
        goodsClient.updateStock(1l, -1);
        log.info("扣减库存----end");

        log.info("增加积分----begin");
        userClient.updatePoint(1l, 10);
        log.info("增加积分----end");

        log.info("修改订单状态----begin");
        this.update(new LambdaUpdateWrapper<Order>().eq(Order::getId, 1l).set(Order::getOrderStatus, 2));
        log.info("修改订单状态----end");
    }
}
